import { $demoi18n } from '@/utils/lang';
import { $message } from '@/utils/util';
import { cloneDeep } from 'lodash';
export default {

  // 清除不需要的传参，防止参数校验报错
  clearParams(params) {
    const _params = cloneDeep(params);
    delete _params.compInfo;
    if (_params.params) {
      _params.params.forEach(n => {
        delete n.sendTime;
      });
    }
    return _params;
  },

  checkApiResTotal(apiRes, params) {
    const { compInfo, pageIndex, pageSize } = params;
    if (!pageIndex && !pageSize && compInfo) { // 不查分页数据，查全量
      const { data, total } = apiRes.data;
      if (data?.length < total) {
        let msg = $demoi18n('api-common.dataMaxExceed');
        msg = msg.replace('{comp}', compInfo.componentName);
        msg = msg.replace('{max}', data.length);
        $message({
          type: 'warning',
          message: msg,
          verticalOffset: 100, // 垂直偏移距离，要个xvue的保存组件提示错开位置
        });
      }
    }
  },

};
